package com.lkc.service.impl;

import com.lkc.annotation.LogMethod;
import com.lkc.bean.ShoppingCar;
import com.lkc.mapper.ShoppingCarDao;
import com.lkc.service.ShoppingCarService;
import com.lkc.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoppingCarServiceImpl implements ShoppingCarService {

    @Autowired
    private ShoppingCarDao shoppingCarDao;

    @Override
    @LogMethod(serviceName = "购物车服务", recordParam = true, recordReturn = true)
    public ShoppingCar add(ShoppingCar shoppingCar) {
        shoppingCarDao.add(shoppingCar);
        return shoppingCarDao.one(shoppingCar.getCarId());
    }

    @Override
    @LogMethod(serviceName = "购物车服务", recordParam = true, recordReturn = true)
    public int del(Integer carId) {
        return shoppingCarDao.del(carId);
    }

    @Override
    @LogMethod(serviceName = "购物车服务", recordParam = true, recordReturn = true)
    public ShoppingCar edit(ShoppingCar shoppingCar) {
        shoppingCarDao.edit(shoppingCar);
        return shoppingCarDao.one(shoppingCar.getCarId());
    }

    @Override
    @LogMethod(serviceName = "购物车服务", recordParam = true, recordReturn = false)
    public List<ShoppingCar> all(ShoppingCar shoppingCar) {
        return shoppingCarDao.all(shoppingCar);
    }

    @Override
    @LogMethod(serviceName = "购物车服务", recordParam = true, recordReturn = true)
    public ShoppingCar one(Integer carId) {
        return shoppingCarDao.one(carId);
    }

    @Override
    @LogMethod(serviceName = "购物车服务", recordParam = true, recordReturn = false)
    public void page(Page page, ShoppingCar shoppingCar) {
        int count = shoppingCarDao.pageCount(shoppingCar);
        Object data = shoppingCarDao.page(page, shoppingCar);
        page.setCount(count);
        page.setData(data);
    }
}
